
cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)
project(DGGSUtility)
if (MSVC)
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
    add_compile_options(/wd4251)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/debug)
else ()
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/release)
endif ()


set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/DGGSUtility)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/DGGSUtility)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/DGGSUtility)

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSBase")

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSKernel")
link_directories("${DGGS_OUT_DIR}/LibDGGSKernel")

include_directories("${CMAKE_SOURCE_DIR}/3rdlibs/include")
link_directories("${CMAKE_SOURCE_DIR}/3rdlibs/lib")

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSFeature")
link_directories("${DGGS_OUT_DIR}/LibDGGSFeature")

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSField")

include_directories("${CMAKE_SOURCE_DIR}/LibGridTIFF")
link_directories("${DGGS_OUT_DIR}/LibGridTIFF")

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSFieldPyramid")
link_directories("${DGGS_OUT_DIR}/LibDGGSFieldPyramid")


add_executable(DGGSUtility
        FieldTranslate.cpp
        FeatureTranslate.cpp
        GridCreate.cpp
        Utility.hpp
        Utility.cpp
        FieldPyramidTranslate.cpp
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(DGGSUtility
            jsoncpp
            gdal_i

            LibDGGSKernelD
            LibDGGSFeatureD
            LibGridTIFFD
            LibDGGSFieldPyramidD
    )
else ()
    target_link_libraries(DGGSUtility
            jsoncpp
            gdal_i

            LibDGGSKernel
            LibDGGSFeature
            LibGridTIFF
            LibDGGSFieldPyramid
    )
endif ()

add_dependencies(DGGSUtility LibDGGSKernel LibDGGSField LibGridTIFF LibDGGSFeature LibDGGSFieldPyramid)

if(ISEXTRACT)
    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        add_custom_command(TARGET DGGSUtility POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/DGGSUtility.exe
                ${lib_output_directory}/bin/debug/DGGSUtility.exe
                COMMENT "Copying DGGSUtility debug executable..."
        )
    else ()
        add_custom_command(TARGET DGGSUtility POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/DGGSUtility.exe
                ${lib_output_directory}/bin/release/DGGSUtility.exe
                COMMENT "Copying DGGSUtility release executable..."
        )
    endif ()
endif()


if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSKernel/LibDGGSKernelD.dll
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSKernelD.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSFeature/LibDGGSFeatureD.dll
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSFeatureD.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSFieldPyramid/LibDGGSFieldPyramidD.dll
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSFieldPyramidD.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibGridTIFF/LibGridTIFFD.dll
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibGridTIFFD.dll)

else ()
    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSKernel/LibDGGSKernel.dll
       ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSKernel.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSFeature/LibDGGSFeature.dll
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSFeature.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibDGGSFieldPyramid/LibDGGSFieldPyramid.dll
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibDGGSFieldPyramid.dll)

    add_custom_command(TARGET DGGSUtility POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
            ${DGGS_OUT_DIR}/LibGridTIFF/LibGridTIFF.dll
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/LibGridTIFF.dll)
endif ()


add_custom_command(TARGET DGGSUtility POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${CMAKE_SOURCE_DIR}/3rdlibs/bin/gdal203.dll
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gdal203.dll)

add_custom_command(TARGET DGGSUtility POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${CMAKE_SOURCE_DIR}/3rdlibs/bin/jsoncpp.dll
    ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jsoncpp.dll)



  
